package com.yonyong.tao.commons.thread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContext;
import java.util.concurrent.CountDownLatch;

/**
 * @Describtion 构建分类路径
 * @Author yonyong
 * @Date 2019/11/15 17:02
 * @Version 1.0.0
 **/
public class BuildPathRunable implements Runnable{
    private final  static Long TIME_STAMP = 30000L;
    private final static Logger logger = LoggerFactory.getLogger(BuildPathRunable.class);
    private ServletContext context = null;
    private final CountDownLatch doneSignal;
    public BuildPathRunable(ServletContext context,CountDownLatch doneSignal){
        this.context = context;
        this.doneSignal = doneSignal;
    }
    @Override
    public void run() {
        WebApplicationContext webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
        try{
            synchronized (doneSignal){
                doneSignal.countDown();
                callBuildPath();
                logger.info("********分类路径构建成功**********");
            }
            doneSignal.await();
        }catch (Exception e){
            logger.error("*****发生异常*******,当前指针"+doneSignal);
            e.printStackTrace();
        }
    }


    /**
     * 构建分类路径
     */
    public void callBuildPath(){
        //执行业务
    }
}
